package com.tianbing.adlottery.controller.supplieradmin;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.jubao.ejb.business.UserBusiness;
import com.jubao.ejb.entity.Product;
import com.tianbing.adlottery.helper.SkinUtils;
import com.tianbing.adlottery.util.UserSession;

/**
 * MultiActionController for admin my store.
 * 
 * @author Conan Chen
 * @since 2007.12.15
 */
public class AdminSupplierController extends MultiActionController {

	Logger logger = Logger.getLogger(AdminSupplierController.class.getName());


	private String suppliedProductListView;

	private UserBusiness userBusiness;

	private SkinUtils skinUtils;

	public ModelAndView listSuppliedProduct(HttpServletRequest request, HttpServletResponse response) throws Exception {

		ModelAndView mv = new ModelAndView(suppliedProductListView);
		Map<String, Object> model = mv.getModel();

		UserSession auth = skinUtils.getUserAuthorization(request, response);
		// get site2content for this store
		Integer pgno = ServletRequestUtils.getIntParameter(request, "pgno", 0);
		Integer pgsize = ServletRequestUtils.getIntParameter(request, "pgsize", 30);

		List<Product> productList = userBusiness.getSuppliedProductList(auth.getUserSysId(), pgno, pgsize);
		long totalCount = userBusiness.getSuppliedProductCount(auth.getUserSysId());
		model.put("productList", productList);

		int pageItemNum = productList == null ? 0 : productList.size();
		String otherParam = null;
		model = skinUtils
				.preparePageFooterParameters(request, pageItemNum, totalCount, pgno, pgsize, otherParam, model);

		return mv;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public void setSuppliedProductListView(String suppliedProductListView) {
		this.suppliedProductListView = suppliedProductListView;
	}

	public void setUserBusiness(UserBusiness userBusiness) {
		this.userBusiness = userBusiness;
	}

	public void setSkinUtils(SkinUtils skinUtils) {
		this.skinUtils = skinUtils;
	}

}
